package com.ihd.ihardware.view.tzc.seller.view;

import android.os.Bundle;
import android.widget.LinearLayout;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ihd.ihardware.R;
import com.ihd.ihardware.databinding.ServiceWdfwFragmentBinding;
import com.ihd.ihardware.view.tzc.main.viewmodel.BalanceViewModel;
import com.just.agentweb.AgentWeb;

import cn.wowjoy.commonlibrary.BuildConfig;
import cn.wowjoy.commonlibrary.app.Constans;
import cn.wowjoy.commonlibrary.base.BaseFragment;
import cn.wowjoy.commonlibrary.utils.SPUtils;

public class WDFWFragment extends BaseFragment<ServiceWdfwFragmentBinding, BalanceViewModel> {
    protected AgentWeb mAgentWeb;

    public WDFWFragment() {
    }

    public static WDFWFragment newInstance(String param1, String param2) {
        WDFWFragment fragment = new WDFWFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }
    }

    @Override
    protected void onCreateViewLazy(Bundle savedInstanceState) {
        String token = SPUtils.getString(Constans.GATEWAY_TOKEN, "");
        JsonObject mParam = new JsonParser().parse(token).getAsJsonObject();

        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(binding.container, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .additionalHttpHeader("amazingToken", mParam.get("userToken").getAsString())
                .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
                .createAgentWeb()
                .ready()
                .go(BuildConfig.HOST + "/marketingcenter/api/v1/serviceHtml/detail");

        mAgentWeb.getAgentWebSettings().getWebSettings().setJavaScriptEnabled(true);
        mAgentWeb.getAgentWebSettings().getWebSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    }

    @Override
    protected void onResumeLazy() {
        mAgentWeb.getWebLifeCycle().onResume();
        super.onResumeLazy();
    }

    @Override
    protected void onPauseLazy() {
        mAgentWeb.getWebLifeCycle().onPause();
        super.onPauseLazy();
    }

    @Override
    protected void onDestroyViewLazy() {
        mAgentWeb.getWebLifeCycle().onDestroy();
        super.onDestroyViewLazy();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.service_wdfw_fragment;
    }

    @Override
    protected Class getViewModelClass() {
        return BalanceViewModel.class;
    }

}
